home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 66.2 KB | 2,246 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UControl.cp
- // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UCONTROL__
- #include "UControl.h"
- #endif
-
- // MacApp
-
- #ifndef __UADORNERS__
- #include "UAdorners.h"
- #endif
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UDRAWINGENVIRONMENT__
- #include "UDrawingEnvironment.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UITERATOR__
- #include "UIterator.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- // ANSI
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- static pascal void ActionProcForTScrollBar(ControlRef aCMgrControl,
- short partCode);
-
- //========================================================================================
- // CLASS CWhileFocused
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // CWhileFocused::new:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void* CWhileFocused::operator new(size_t /*size*/)
- {
- // prevent heap-based allocation
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CWhileFocused::delete:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void CWhileFocused::operator delete(void*)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CWhileFocused::CWhileFocused:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- CWhileFocused::CWhileFocused(TCtlMgr * itsCtlMgr, Boolean redraw) :
- fCtlMgr(itsCtlMgr),
- fRedraw(redraw)
- {
- // Setup the FailInfo to catch any failures while this object is in scope
- fFailInfo.SetCleanupProc(CWhileFocused::CallCleanup, this);
-
- fDidFocus = FALSE;
- if (fCtlMgr->fCMgrControl)
- {
- if (fRedraw && fCtlMgr->Focus())
- {
- fDidFocus = TRUE;
-
- CRect qdArea(fCtlMgr->ControlQDArea());
-
- Boolean wasVisible = fCtlMgr->SetCMgrVisibility(FALSE);
- fOldControlLocation = ((CRect&)(*fCtlMgr->fCMgrControl)->contrlRect)[topLeft]; // I'd rather have an accessor!!!
- MoveControl(fCtlMgr->fCMgrControl, qdArea.left, qdArea.top); //SRF
- fCtlMgr->SetCMgrVisibility(wasVisible);
- }
- else
- fWasVisible = fCtlMgr->SetCMgrVisibility(FALSE);
- }
- } // CWhileFocused::CWhileFocused
-
- //----------------------------------------------------------------------------------------
- // CWhileFocused::~CWhileFocused:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- CWhileFocused::~CWhileFocused()
- {
- this->Cleanup();
-
- fFailInfo.Success();
- } // CWhileFocused::~CWhileFocused
-
- //----------------------------------------------------------------------------------------
- // CWhileFocused::Cleanup:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void CWhileFocused::Cleanup()
- {
- if (fCtlMgr->fCMgrControl)
- if (fDidFocus)
- {
- Boolean wasVisible = fCtlMgr->SetCMgrVisibility(FALSE);
- MoveControl(fCtlMgr->fCMgrControl, fOldControlLocation.h, fOldControlLocation.v); //SRF
- fCtlMgr->SetCMgrVisibility(wasVisible);
- }
- else
- fCtlMgr->SetCMgrVisibility(fWasVisible); // …restore visibility
- } // CWhileFocused::Cleanup
-
- //----------------------------------------------------------------------------------------
- // CWhileFocused::CallCleanup:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- /*static*/ void CWhileFocused::CallCleanup(void* context)
- {
- ((CWhileFocused*) context)->Cleanup();
- } // CWhileFocused::CallCleanup
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // ActionProcForTScrollBar:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- pascal void ActionProcForTScrollBar(ControlRef aCMgrControl,
- short partCode)
- {
- TScrollBar * aScrollBar;
-
- aScrollBar = (TScrollBar *)(GetControlReference(aCMgrControl));
- FailNIL(aScrollBar); // What else you gonna' do?
-
- aScrollBar->ActionProc(partCode);
-
- } // ActionProcForTScrollBar
-
-
- //========================================================================================
- // CLASS TControlTracker
- //========================================================================================
- #undef Inherited
- #define Inherited TTracker
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TControlTracker, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TControlTracker constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- TControlTracker::TControlTracker()
- {
- fControl = NULL;
- fTrackNonMovement = TRUE;
- fViewConstrain = FALSE;
- } // TControlTracker::TControlTracker
-
- //----------------------------------------------------------------------------------------
- // TControlTracker destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TControlTracker::~TControlTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TControlTracker::IControlTracker:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TControlTracker::IControlTracker(TControl* theControl,
- const VPoint& itsMouse)
- {
- this->ITracker(cTrackingControl, theControl, kCantUndo, kDoesNotCauseChange, NULL,
- theControl, theControl->GetScroller(kImmediateSuperView), itsMouse);
- #if qDebug
- if (theControl == NULL)
- ProgramBreak("Control passed to IControlTracker can''t be NULL.");
- #endif
-
- fControl = theControl;
- } // TControlTracker::IControlTracker
-
-
- //========================================================================================
- // CLASS TControl
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TControl, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TControl constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TControl::TControl()
- {
- fEventNumber = mOKHit;
- fHilite = FALSE;
- fDimmed = FALSE;
- fSizeable = TRUE;
- fInset = gZeroVRect;
- fTextStyle = gSystemStyle;
- fTextStyleRsrcID = kNoResource;
- fPreferOutline = kDontPreferOutline;
- } // TControl::TControl
-
- //----------------------------------------------------------------------------------------
- // TControl destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TControl::~TControl()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TControl::IControl:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TControl::IControl(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const TextStyle& itsTextStyle)
- {
- TDocument * itsDocument = NULL;
-
- #if qDebug
- if ((itsSize.h > kMaxCoord) || (itsSize.v > kMaxCoord))
- {
- char msg[128];
-
- sprintf(msg, "The size in pixels of a TControl cannot exceed %ld\n", kMaxCoord);
- ProgramBreak(msg);
- }
- #endif
-
- if (itsSuperView)
- itsDocument = itsSuperView->fDocument;
-
- this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- fTextStyle = itsTextStyle;
- } // TControl::IControl
-
- //----------------------------------------------------------------------------------------
- // TControl::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TControl::GetStandardSignature() // override
- {
- return kStdControl;
- } // TControl::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TControl::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TControl::ReadFields(TStream* aStream) // override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fEventNumber = aStream->ReadLong();
-
- // set various flags
- this->HiliteState(aStream->ReadBoolean(), kDontRedraw);
- this->DimState(aStream->ReadBoolean(), kDontRedraw);
- fSizeable = aStream->ReadBoolean();
-
- VRect itsInset;
- aStream->ReadVRect(itsInset);
- fInset = itsInset;
-
- fTextStyleRsrcID = aStream->ReadInteger();
- if (fTextStyleRsrcID != kNoResource)
- {
- TextStyle itsTextStyle;
- MAGetTextStyle(fTextStyleRsrcID, itsTextStyle);
- fTextStyle = itsTextStyle;
- }
-
- fPreferOutline = aStream->ReadBoolean();
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
-
- #if qDebug
- if ((fSize.h > kMaxCoord) || (fSize.v > kMaxCoord))
- {
- char msg[128];
-
- sprintf(msg, "The size in pixels of a TControl cannot exceed %ld\n", kMaxCoord);
- ProgramBreak(gEmptyString);
- }
- #endif
- } // TControl::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TControl::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TControl::WriteFields(TStream* aStream) // override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteLong(fEventNumber); // write its fEventNumber
-
- aStream->WriteBoolean(fHilite);
- aStream->WriteBoolean(fDimmed);
- aStream->WriteBoolean(fSizeable);
-
- aStream->WriteVRect(fInset); // write its inset
-
- aStream->WriteInteger(fTextStyleRsrcID);
-
- aStream->WriteBoolean(fPreferOutline);
- } // TControl::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TControl::ComputeFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TControl::ComputeFrame(VRect& newFrame)// override
- {
- Inherited::ComputeFrame(newFrame);
- if (!fSizeable)
- {
- // …we need to adjust the bot/right offset
- // If view is going to change size, then doesn't change control's actual size
- fInset[botRight] += newFrame.GetSize() - fSize;
- }
- } // TControl::ComputeFrame
-
- //----------------------------------------------------------------------------------------
- // TControl::ContainsMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- Boolean TControl::ContainsMouse(const VPoint& theMouse)// override
- {
- VRect aRect;
- this->ControlArea(aRect);
-
- return aRect.Contains(theMouse) && Inherited::ContainsMouse(theMouse);
- } // TControl::ContainsMouse
-
- //----------------------------------------------------------------------------------------
- // TControl::ControlArea:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TControl::ControlArea(VRect& theArea)
- {
- VRect itsExtent(this->GetExtent());
- theArea = VRect(itsExtent[topLeft] + fInset[topLeft], itsExtent[botRight] - fInset[botRight]);
-
- CntlAdornment itsAdornment;
- this->GetAdornment(itsAdornment);
- if (macroIn(itsAdornment, adnShadow))
- {
- CPoint itsPenSize;
- this->GetPenSize(itsPenSize);
- theArea[botRight] -= VPoint(itsPenSize);
- }
- } // TControl::ControlArea
-
- //----------------------------------------------------------------------------------------
- // TControl::ControlQDArea:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- CRect TControl::ControlQDArea()
- {
- VRect theArea;
- this->ControlArea(theArea);
- return this->ViewToQDRect(theArea);
- } // TControl::ControlQDArea
-
- //----------------------------------------------------------------------------------------
- // TControl::Dim:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TControl::Dim()
- {
- #if qDebug
- this->AssumeFocused();
- #endif
-
- PenPat(&qd.gray);
- PenMode(patBic);
- PaintRect(&this->ControlQDArea());
- } // TControl::Dim
-
- //----------------------------------------------------------------------------------------
- // TControl::DimState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::DimState(Boolean state, Boolean redraw)
- {
- if (state != fDimmed)
- {
- fDimmed = state;
- if (state) // dim adorner draws the dim state
- this->AddAdorner(gDimAdorner, kAdornLast - 10, kDontRedraw);
- else
- this->DeleteAdorner(gDimAdorner, kDontRedraw);
- if (redraw)
- this->DrawContents(); // Draw change immediately
- }
- } // TControl::DimState
-
- //----------------------------------------------------------------------------------------
- // TControl::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TControl::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* ,
- CPoint) // override
- {
- TControlTracker * aControlTracker = new TControlTracker;
- aControlTracker->IControlTracker(this, theMouse);
- this->PostCommand(aControlTracker);
- } // TControl::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TControl::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TControl::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event) // override
-
- {
- switch (eventNumber)
- {
- case mTurnOn:
- this->HiliteState(TRUE,kRedraw);
- break;
- case mTurnOff:
- this->HiliteState(FALSE,kRedraw);
- break;
- case mToggle:
- this->HiliteState(!fHilite,kRedraw);
- break;
- default:
- Inherited::DoEvent(eventNumber, source, event);
- break;
- }
- } // TControl::DoEvent
-
- //----------------------------------------------------------------------------------------
- // TControl::Flash:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TControl::Flash()
- {
- long dontCare;
-
- this->HiliteState(TRUE, kRedraw);
- Delay(8, &dontCare);
- this->HiliteState(FALSE, kRedraw);
- } // TControl::Flash
-
- //----------------------------------------------------------------------------------------
- // TControl::Focus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- Boolean TControl::Focus() // override
- {
- if (Inherited::Focus())
- {
- TextStyle aTextStyle = fTextStyle;
- SetPortTextStyle(aTextStyle);
- PenNormal();
- return TRUE;
- }
- else
- return FALSE;
- } // TControl::Focus
-
- //----------------------------------------------------------------------------------------
- // TControl::Hilite:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TControl::Hilite()
- {
- #if qDebug
- this->AssumeFocused();
- #endif
-
- InvertRect(&this->ControlQDArea());
- } // TControl::Hilite
-
- //----------------------------------------------------------------------------------------
- // TControl::HiliteState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::HiliteState(Boolean state, Boolean redraw)
- {
- if (state != fHilite)
- {
- fHilite = state;
- if (state) // hilite adorner draws the hilite state
- this->AddAdorner(gHiliteAdorner, kAdornLast - 5, kDontRedraw);
- else
- this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
- if (redraw && this->IsDrawable())
- this->Hilite();
- }
- } // TControl::HiliteState
-
- //----------------------------------------------------------------------------------------
- // TControl::Inset:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::Inset(const VPoint& delta, Boolean redraw)
- {
- if (fSizeable)
- {
- fInset += delta;
-
- if (redraw)
- this->ForceRedraw();
- }
- } // TControl::Inset
-
- //----------------------------------------------------------------------------------------
- // TControl::InstallColor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::InstallColor(const CRGBColor& theColor, Boolean redraw)
- {
- fTextStyle.tsColor = theColor;
- if (redraw)
- this->DrawContents();
- } // TControl::InstallColor
-
-
- //----------------------------------------------------------------------------------------
- // TControl::InstallTextStyle:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::InstallTextStyle(const TextStyle& theTextStyle, Boolean redraw)
- {
- fTextStyle = theTextStyle;
- if (redraw)
- this->DrawContents();
- } // TControl::InstallTextStyle
-
- //----------------------------------------------------------------------------------------
- // TControl::IsDimmed:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- Boolean TControl::IsDimmed()
- {
- return fDimmed;
- } // TControl::IsDimmed
-
- //----------------------------------------------------------------------------------------
- // TControl::SetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::SetFrame(const VRect& newFrame, Boolean invalidate) // override
- {
-
- VPoint oldSize = fSize;
-
- Inherited::SetFrame(newFrame, invalidate);
-
- // If we need to invalidate, then invalidate the whole view rather than
- // the difference between the old and new size.
- if (invalidate && fSize != oldSize)
- this->ForceRedraw();
- } // TControl::SetFrame
-
- //----------------------------------------------------------------------------------------
- // TControl::GetAdornExtent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TControl::GetAdornExtent(VRect& itsAdornExtent)// override
- {
- itsAdornExtent = this->GetExtent();
-
- CntlAdornment itsAdornment;
- this->GetAdornment(itsAdornment);
- if (macroIn(itsAdornment, adnShadow))
- {
- CPoint itsPenSize;
- this->GetPenSize(itsPenSize);
- itsAdornExtent[botRight] -= VPoint(itsPenSize);
- }
- } // TControl::GetAdornExtent
-
- //----------------------------------------------------------------------------------------
- // TControl::GetEventNumber:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- EventNumber TControl::GetEventNumber() // Override
- {
- return fEventNumber;
- } // TControl::GetEventNumber
-
- //----------------------------------------------------------------------------------------
- // TControl::SetAdornment:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::SetAdornment(/*CntlAdornment*/ short newAdornment, Boolean redraw)
- //!!! Using short rather than CntlAdornment because of a compiler bug
- {
- TCompatibilityAdorner* itsAdorner = (TCompatibilityAdorner*)this->AdornerWithID(kCompatibilityAdorner);
- if (itsAdorner == NULL)
- {
- if (newAdornment != 0)
- {
- itsAdorner = new TCompatibilityAdorner;
- itsAdorner->ICompatibilityAdorner(newAdornment);
- this->AddAdorner(itsAdorner, kAdornAfter, redraw);
- }
- }
- else
- {
- itsAdorner->fAdornment = newAdornment;
- if (redraw)
- this->ForceRedraw();
- }
- } // TControl::SetAdornment
-
- //----------------------------------------------------------------------------------------
- // TControl::GetAdornment:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::GetAdornment(CntlAdornment& itsAdornment)
- {
- TAdorner* itsAdorner = this->AdornerWithID(kCompatibilityAdorner);
- itsAdornment = 0;
- if (itsAdorner)
- itsAdornment = ((TCompatibilityAdorner*)itsAdorner)->fAdornment;
- } // TControl::GetAdornment
-
- //----------------------------------------------------------------------------------------
- // TControl::SetPenSize:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::SetPenSize(CPoint newPenSize)
- {
- if (newPenSize != CPoint(1,1))
- {
- this->CreateDrawingEnvironment();
- fDrawingEnvironment->fPenSize = newPenSize;
- }
- } // TControl::SetPenSize
-
- //----------------------------------------------------------------------------------------
- // TControl::GetPenSize:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::GetPenSize(CPoint& itsPenSize)
- {
- if (fDrawingEnvironment)
- itsPenSize = fDrawingEnvironment->fPenSize;
- else
- itsPenSize = CPoint(1,1);
- } // TControl::GetPenSize
-
- //----------------------------------------------------------------------------------------
- // TControl::SetInset:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TControl::SetInset(const VRect& newInset, Boolean redraw)
- {
- if (fSizeable)
- {
- fInset = newInset;
-
- // this->Resize(fSize.Copy(), redraw);
- if (redraw)
- this->ForceRedraw();
- }
- } // TControl::SetInset
-
- //----------------------------------------------------------------------------------------
- // TControl::TrackFeedback:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TControl::TrackFeedback(TrackPhase /* aTrackPhase */,
- const VPoint& /* anchorPoint */,
- const VPoint& /* previousPoint */,
- const VPoint& /* nextPoint */,
- Boolean /* mouseDidMove */,
- Boolean /* turnItOn */)
-
- {
- // do nothing
- } // TControl::TrackFeedback
-
- //----------------------------------------------------------------------------------------
- // TControl::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TControl::TrackMouse(TrackPhase aTrackPhase,
- VPoint& /* anchorPoint */,
- VPoint& /* previousPoint */,
- VPoint& nextPoint,
- Boolean /* mouseDidMove */)
- {
- switch (aTrackPhase)
- {
- case trackBegin:
- this->HiliteState(TRUE, kRedraw);
- break;
- case trackContinue:
- this->HiliteState(this->ContainsMouse(nextPoint), kRedraw);
- break;
- case trackEnd:
- if (this->ContainsMouse(nextPoint))
- {
- switch (fEventNumber)
- {
- // The defchoice determines different kinds of tracking behavior
- case mCheckBoxHit:
- // Toggle highlighting
- this->HandleEvent(mToggle,this,NULL);
- break;
- case mRadioHit:
- // Once it's on, it's on, until a cluster turns it off
- this->HandleEvent(mTurnOn,this,NULL);
- break;
- default:
- // Button action. Turn off highlighting.
- this->HandleEvent(mTurnOff,this,NULL);
- break;
- }
- this->HandleEvent(fEventNumber, this, NULL);
- }
- break;
- }
- } // TControl::TrackMouse
-
-
- //========================================================================================
- // CLASS TCtlMgr
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TCtlMgr, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TCtlMgr::TCtlMgr()
- {
- fCMgrControl = NULL;
-
- // These MUST be initialized because SetLongValues tests each new value against
- // the old value before doing anything. If the fLongMax value should happen to
- // have a (bogus - uninitialized) value that matches itsMax, fBitsToShift won't
- // be initialized and the control manager control will behave erratically.
- fBitsToShift = 0;
- fLongVal = 0;
- fLongMin = 0;
- fLongMax = 0;
- fProcID = 0;
- } // TCtlMgr::TCtlMgr
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::ICtlMgr:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TCtlMgr::ICtlMgr(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const CStr255& itsTitle,
- long itsVal,
- long itsMin,
- long itsMax,
- short itsProcID,
- const TextStyle& itsTextStyle)
- {
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
-
- FailInfo fi;
- Try(fi)
- {
- this->CreateCMgrControl(itsTitle, itsVal, itsMin, itsMax, itsProcID);
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TCtlMgr::ICtlMgr
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- TObject* TCtlMgr::Clone() // override
- {
- MAVolatileInit(TCtlMgr*, aClonedCtlMgr, (TCtlMgr *)(Inherited::Clone()));
-
- if (fCMgrControl)
- {
- // Copy the control values to locals and then set the values in the TCtlMgr to
- // zero. The SetLongxxx routines check to see if the control values have changed
- // before actual changing the toolbox control.
-
- aClonedCtlMgr->fLongMin = aClonedCtlMgr->fLongMax = aClonedCtlMgr->fLongVal = 0;
-
- CStr255 contrlTitle;
- GetControlTitle(fCMgrControl, contrlTitle);
-
- FailInfo fi;
- Try(fi)
- {
- aClonedCtlMgr->CreateCMgrControl(contrlTitle, fLongVal, fLongMin, fLongMax, fProcID);
- fi.Success();
- }
- else
- {
- aClonedCtlMgr->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedCtlMgr;
- } // TCtlMgr::Clone
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TCtlMgr::~TCtlMgr()
- {
- if (fCMgrControl)
- {
- this->SetCMgrVisibility(FALSE); // This insures that HideControl, which
- // will be called by SizeControl, doesn't
- // do anything. HideControl seems to have
- // some problems with large (~>
- // 14000x14000)
- SizeControl(fCMgrControl, 0, 0); // Prevent CMgr from erasing the control!
- DisposeControl(fCMgrControl);
- fCMgrControl = NULL; // So BeInPort and others will be happy!
- }
- } // TCtlMgr::Free
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::BeInPort:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::BeInPort(GrafPtr itsPort) // override
- {
- Inherited::BeInPort(itsPort);
-
- if (fCMgrControl)
- {
- WindowRef itsNewControlOwner;
- if (!itsPort)
- {
- this->SetCMgrVisibility(FALSE);
- itsNewControlOwner = (WindowRef)gWorkPort;
- }
- else
- {
- this->SetCMgrVisibility(TRUE);
- itsNewControlOwner = (WindowRef)itsPort;
- }
-
- //
- // Get the control pointing at the owning window
- //
- WindowRef itsOldControlOwner = (*fCMgrControl)->contrlOwner;
- (*fCMgrControl)->contrlOwner = gWorkPort; // in case it's not anywhere else
-
- //
- // Get the control off the control list of the old owner
- //
- if (itsOldControlOwner)
- {
- // first control on list
- if (((WindowPeek)itsOldControlOwner)->controlList == fCMgrControl)
- {
- ((WindowPeek)itsOldControlOwner)->controlList = (*fCMgrControl)->nextControl;
- }
- else
- {
- ControlHandle currentControl = ((WindowPeek)itsOldControlOwner)->controlList;
- while (currentControl)
- {
- if ((*currentControl)->nextControl == fCMgrControl)
- {
- (*currentControl)->nextControl = (*fCMgrControl)->nextControl;
- break;
- }
- currentControl = (*currentControl)->nextControl;
- }
- }
- }
-
- //
- // and on to the control list of the new owner
- //
- if (itsNewControlOwner)
- {
- TWindow* itsWindow = this->GetWindow();
- if (itsWindow && itsWindow->fWMgrWindow == itsNewControlOwner)
- {
- #if 0
- (*fCMgrControl)->nextControl = GetControlOwningWindowControlList(itsNewControlOwner);
- GetControlOwningWindowControlList(itsNewControlOwner) = fCMgrControl;
- #else
-
- (*fCMgrControl)->nextControl = ((WindowPeek)itsNewControlOwner)->controlList;
- ((WindowPeek)itsNewControlOwner)->controlList = fCMgrControl;
- #endif
-
-
- (*fCMgrControl)->contrlOwner = itsNewControlOwner;
- }
- }
-
- }
- } // TCtlMgr::BeInPort
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::CreateCMgrControl:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TCtlMgr::CreateCMgrControl(const CStr255& itsTitle,
- long itsVal,
- long itsMin,
- long itsMax,
- short itsProcID)
- {
- TWindow* itsTWindow = this->GetWindow();
- WindowRef itsWindow = itsTWindow ? itsTWindow->fWMgrWindow : gWorkPort;
-
- fProcID = itsProcID;
-
- ControlRef aCMgrControl = NewControl(itsWindow, this->ControlQDArea(), itsTitle, FALSE, 0, 0, 0, itsProcID, (long)this);
- FailNIL(aCMgrControl);
-
- fCMgrControl = aCMgrControl;
- this->DimState(fDimmed, kDontRedraw);
- this->HiliteState(fHilite, kDontRedraw);
-
- // Remember, the control was created with zeros, fix it up.
- this->SetLongValues(itsVal, itsMin, itsMax, kDontRedraw);
-
- this->SetCMgrVisibility(itsWindow != gWorkPort);
- } // TCtlMgr::CreateCMgrControl
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::InstallColor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::InstallColor(const CRGBColor& theColor, Boolean redraw)
- {
- if ((qNeedsColorQD || HasColorQD()) && fCMgrControl)
- {
- // retrieve the control's color table
- AuxCtlHandle itsAuxCtlHandle;
- Boolean hasAuxCtl = GetAuxiliaryControlRecord(fCMgrControl, &itsAuxCtlHandle);
- FailNIL(itsAuxCtlHandle);
- CCTabHandle colorTableHandle = (*itsAuxCtlHandle)->acCTable;
- FailNIL(colorTableHandle);
-
- // determine if the control color table needs to be changed
- Boolean changeColorTable = TRUE;
-
- // The ctSize field defines the number of elements in the table, minus one.
- for (short i = 0; i <= (*colorTableHandle)->ctSize; ++i)
- {
- if ((*colorTableHandle)->ctTable[i].value == cFrameColor)
- {
- changeColorTable = CRGBColor((*colorTableHandle)->ctTable[i].rgb) != theColor;
- break;
- }
- }
-
- // modify the color table if necessary
- if (changeColorTable)
- {
- PermHandToHand((Handle &) colorTableHandle);
-
- // Parse the color table, and make the appropriate settings.
- // The ctSize field defines the number of elements in the table, minus one.
- for (short i = 0; i <= (*colorTableHandle)->ctSize; ++i)
- {
- switch ((*colorTableHandle)->ctTable[i].value)
- {
- case cFrameColor:
- case cTextColor:
- (*colorTableHandle)->ctTable[i].rgb = theColor;
- break;
- case cThumbColor:
- case cBodyColor:
- break; // do nothing - InstallColor only affects the "fore" color
- }
- }
-
- // set the new color table
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- SetControlColor(fCMgrControl, colorTableHandle);
- }
- }
-
- Inherited::InstallColor(theColor, redraw);
- } // TCtlMgr::InstallColor
-
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::DimState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::DimState(Boolean state, Boolean redraw) // override
- {
- if (fCMgrControl && (*fCMgrControl)->contrlHilite != (state ? 255 : 0))
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- HiliteControl(fCMgrControl, state ? 255 : 0);
- }
- fDimmed = state;
- } // TCtlMgr::DimState
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TCtlMgr::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* /* event */,
- CPoint /* hysteresis */) // override
- {
- CPoint theQDMouse(this->ViewToQDPt(theMouse));
-
- if (fCMgrControl)
- {
- CWhileFocused itsWhileFocused(this, kRedraw);
- if (TestControl(fCMgrControl, theQDMouse) != 0)
- {
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- short trackResult = TrackControl(fCMgrControl, theQDMouse, (ControlActionUPP)(-1));
-
- if (trackResult != 0)
- {
- long newLongValue;
-
- if (this->GetVal() == this->GetMax())
- newLongValue = fLongMax;
- else
- newLongValue = ((long)GetVal() << fBitsToShift);
- this->SetLongVal(newLongValue, kRedraw);
-
- this->HandleEvent(fEventNumber, this, NULL);
-
- gDispatcher->InvalidateMouseRegions();
- }
- }
- }
- } // TCtlMgr::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::Draw(const VRect& area) // override
- {
- if (this->IsCMgrVisible())
- {
- #if qDebug
- this->AssumeFocused();
- #endif
- // for controls, spool the picture and draw that to overcome font problems
- PicHandle aPH = NULL;
- if (gPrinting)
- {
- GrafPtr printPort = qd.thePort;
- // spool picture, take care as this will call TCtlMgr.Draw()
- gPrinting = FALSE;
- aPH = this->AsPictForPrinting();
- gPrinting = TRUE;
- // if success, print this picture
- if (aPH)
- {
- SetPort(printPort);
- DrawPicture(aPH, &this->GetQDExtent());
- DisposeIfPicHandle(aPH);
- }
- }
-
- // if spooling failed, or not printing, use Draw1Control()
- if (! gPrinting || aPH == NULL)
- {
- // save/set/reset the port in case we're imaging in some other port
- WindowRef savedOwner = (*fCMgrControl)->contrlOwner;
- (*fCMgrControl)->contrlOwner = (WindowRef)qd.thePort; //NOTE: !!! Still needs proper fix, SRF
-
- CWhileFocused itsWhileFocused(this, kRedraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- PenNormal();
- Draw1Control(fCMgrControl);
-
- // restore control owner
- (*fCMgrControl)->contrlOwner = savedOwner;
- }
- }
-
- Inherited::Draw(area); // to get adornment
- } // TCtlMgr::Draw
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::AsPictForPrinting:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- PicHandle TCtlMgr::AsPictForPrinting()
- {
- // this code is very similar to TView.AsPict(), but to make sure nothing else breaks,
- // I made it into a separate method.
-
- MAVolatileInit(PicHandle, pHndl, NULL);
- MAVolatileInit(Boolean, pictureIsOpen, FALSE);
-
- CRect aRect(qd.thePort->portRect);
-
- SetPortWindowPort(gWorkPort);
- PortSize(aRect.GetLength(hSel), aRect.GetLength(vSel));
- MovePortTo(aRect.right, aRect.top);
-
- this->InvalidateFocus();
- gDrawingPictScrap = TRUE;
- gDrawingPictScrapView = this;
- SetPortWindowPort(gWorkPort);
- this->BeInPort((GrafPtr)GetWindowPort(gWorkPort));
-
- FailInfo fi;
- Try(fi)
- {
- if (this->Focus())
- {
- CRect qdExtent(this->GetQDExtent());
- pHndl = OpenPicture(qdExtent);
- pictureIsOpen = TRUE; // Failure handler needs to close it
- FailNIL(pHndl);
-
- ClipRect(qdExtent);
- this->DrawContents();
- ClosePicture();
- pictureIsOpen = FALSE; // Failure handler doesn't need to close it
-
- // On the 128K ROMs the picFrame will be empty if drawing the
- // picture failed. On the 64K ROM's QuickDraw simply bombs.
- if (((CRect &) (*pHndl)->picFrame).Empty())
- {
- #if qDebug
- fprintf(stderr, "Picture frame is empty!\n");
- #endif
- FailOSErr(memFullErr);
- }
-
- this->InvalidateFocus();
- }
- #if qDebug
- else // can't focus
- ProgramBreak("Can't focus view while spooling picture for printing");
- #endif
-
- fi.Success();
- }
- else
- {
- if (pHndl)
- {
- if (pictureIsOpen)
- ClosePicture();
- pHndl = DisposeIfPicHandle(pHndl);
- }
- }
-
- SetPortWindowPort(gWorkPort);
- PortSize(0, 0);
- gDrawingPictScrap = FALSE;
- gDrawingPictScrapView = NULL;
-
- // if NULL is returned, Draw1Control() will be used
- return pHndl;
-
- } // TCtlMgr::AsPictForPrinting
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::IsCMgrVisible:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- Boolean TCtlMgr::IsCMgrVisible()
- {
- return (fCMgrControl && ((*fCMgrControl)->contrlVis == 255));
- } // TCtlMgr::IsCMgrVisible
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetMax:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- short TCtlMgr::GetMax()
- {
- return fCMgrControl ? GetControlMaximum(fCMgrControl) : 0;
- } // TCtlMgr::GetMax
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetMin:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- short TCtlMgr::GetMin()
- {
- return fCMgrControl ? GetControlMinimum(fCMgrControl) : 0;
- } // TCtlMgr::GetMin
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetText:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::GetText(CStr255& theText)
- {
- if (fCMgrControl)
- GetControlTitle(fCMgrControl, theText);
- else
- theText.Empty();
- } // TCtlMgr::GetText
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetVal:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- short TCtlMgr::GetVal()
- {
- return fCMgrControl ? GetControlValue(fCMgrControl) : 0;
- } // TCtlMgr::GetVal
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetVariant:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- short TCtlMgr::GetVariant()
- {
- return fCMgrControl ? GetControlVariant(fCMgrControl) : 0;
- } // TCtlMgr::GetVariant
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::HiliteState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::HiliteState(Boolean state, Boolean redraw) // override
- {
- // if the control is dimmed, leave it alone!
- if (fCMgrControl && (*fCMgrControl)->contrlHilite != 255 && fHilite != (*fCMgrControl)->contrlHilite != (state * 10))
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- HiliteControl(fCMgrControl, state * 10);
- }
- fHilite = state;
- } // TCtlMgr::HiliteState
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::Inset:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::Inset(const VPoint& delta, Boolean redraw) // override
- {
- Inherited::Inset(delta, kDontRedraw);
-
- this->AdjustCtlMgrControl(redraw);
- } // TCtlMgr::Inset
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetInset:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::SetInset(const VRect& newInset, Boolean redraw)
- {
- Inherited::SetInset(newInset, kDontRedraw);
-
- this->AdjustCtlMgrControl(redraw);
- } // TCtlMgr::SetInset
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::AdjustCtlMgrControl:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::AdjustCtlMgrControl(Boolean redraw)
- {
- if (fCMgrControl)
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- CRect qdArea(this->ControlQDArea());
-
- MoveControl(fCMgrControl, qdArea.left, qdArea.top);
- if (fSizeable)
- SizeControl(fCMgrControl, abs(qdArea.GetLength(hSel)), abs(qdArea.GetLength(vSel)));
- }
- } // TCtlMgr::AdjustCtlMgrControl
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::SetFrame(const VRect& newFrame, Boolean invalidate) // override
- {
- VRect oldFrame(this->GetFrame());
-
- Inherited::SetFrame(newFrame, invalidate);
-
- if (newFrame != oldFrame)
- AdjustCtlMgrControl(invalidate);
- } // TCtlMgr::SetFrame
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetCMgrVisibility:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- Boolean TCtlMgr::SetCMgrVisibility(Boolean beVisible)
- {
- Boolean returnVal = this->IsCMgrVisible();
-
- if (fCMgrControl)
- if (beVisible)
- (*fCMgrControl)->contrlVis = 255;
- else
- (*fCMgrControl)->contrlVis = 0;
-
- return returnVal;
- } // TCtlMgr::SetCMgrVisibility
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::Show:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::Show(Boolean state, Boolean redraw)
- {
- this->SetCMgrVisibility(state);
-
- Inherited::Show(state, redraw);
- } // TCtlMgr::Show
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetMax:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetMax(short itsMax, Boolean redraw)
- {
- if (fCMgrControl && GetControlMaximum(fCMgrControl) != itsMax)
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- SetControlMaximum(fCMgrControl, itsMax);
- }
- } // TCtlMgr::SetMax
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetMin:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetMin(short itsMin, Boolean redraw)
- {
- if (fCMgrControl && GetControlMinimum(fCMgrControl) != itsMin)
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- SetControlMinimum(fCMgrControl, itsMin);
- }
- } // TCtlMgr::SetMin
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetText:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TCtlMgr::SetText(const CStr255& itsText, Boolean redraw)
- {
- CStr255 currentText;
-
- if (fCMgrControl)
- {
- this->GetText(currentText);
- if (CompareStrings(currentText, itsText) != 0)
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- SetControlTitle(fCMgrControl, itsText);
- if (this->IsFocused()) // we were focused if redraw was true
- {
- CRect r = (*(fCMgrControl))->contrlRect;
- this->ValidateRect(r); // Because Control Manager invalidates it.
- }
- }
- }
- } // TCtlMgr::SetText
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetVal:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetVal(short newVal, Boolean redraw)
- {
- if (fCMgrControl && GetControlValue(fCMgrControl) != newVal)
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- SetControlValue(fCMgrControl, newVal);
- }
- } // TCtlMgr::SetVal
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetValues:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetValues(short itsVal,
- short itsMin,
- short itsMax,
- Boolean redraw)
- {
- if (fCMgrControl)
- {
- CWhileFocused itsWhileFocused(this, redraw);
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- SetControlMinimum(fCMgrControl, itsMin);
- SetControlMaximum(fCMgrControl, itsMax);
- SetControlValue(fCMgrControl, itsVal);
- }
- } // TCtlMgr::SetValues
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetLongMax:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- VCoordinate TCtlMgr::GetLongMax()
- {
- return fLongMax;
- } // TCtlMgr::GetLongMax
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetLongMin:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- VCoordinate TCtlMgr::GetLongMin()
- {
- return fLongMin;
- } // TCtlMgr::GetLongMin
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetLongVal:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- VCoordinate TCtlMgr::GetLongVal()
- {
- return fLongVal;
- } // TCtlMgr::GetLongVal
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetLongMax:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetLongMax(VCoordinate itsMax, Boolean redraw)
- {
- if (itsMax != fLongMax)
- {
- fLongMax = itsMax;
- fBitsToShift = 0;
- while (itsMax > SHRT_MAX)
- {
- itsMax = ((itsMax) >> 1);
- ++fBitsToShift;
- }
- this->SetMax((short)itsMax, redraw);
- if (fLongMax < fLongVal) {
- this->SetLongVal(fLongMax, redraw);
- }
- }
- } // TCtlMgr::SetLongMax
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetLongMin:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetLongMin(VCoordinate itsMin, Boolean redraw)
- {
- if (itsMin != fLongMin)
- {
- fLongMin = itsMin;
- this->SetMin((short)(itsMin >> fBitsToShift), redraw);
- if (fLongMin > fLongVal) {
- this->SetLongVal(fLongMin, redraw);
- }
- }
- } // TCtlMgr::SetLongMin
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetLongVal:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetLongVal(VCoordinate itsVal, Boolean redraw)
- {
- itsVal = MinMax(fLongMin, itsVal, fLongMax);
- if (itsVal != fLongVal)
- {
- fLongVal = itsVal;
- this->SetVal((short)(itsVal >> fBitsToShift), redraw);
- }
- } // TCtlMgr::SetLongVal
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::SetLongValues:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::SetLongValues(VCoordinate itsVal,
- VCoordinate itsMin,
- VCoordinate itsMax,
- Boolean redraw)
- {
- this->SetLongMax(itsMax, redraw); // Must be first to get fBitsToShift setup
- this->SetLongMin(itsMin, redraw);
- this->SetLongVal(itsVal, redraw);
- } // TCtlMgr::SetLongValues
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::GetHelpState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- short TCtlMgr::GetHelpState()
- {
- short helpState;
-
- if (this->IsEnabled())
- {
- short ctlValue = this->GetVal();
- if (ctlValue == 1)
- helpState = kHMCheckedItem;
- else
- if (ctlValue > 1)
- helpState = kHMOtherItem;
- else
- helpState = kHMEnabledItem;
- }
- else
- helpState = kHMDisabledItem;
-
- return helpState;
- }
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr::UpdateCoordinates:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TCtlMgr::UpdateCoordinates()// override
- {
- CPoint oldQDOrigin(fQDOrigin);
- VPoint oldViewToQDOffset(fViewToQDOffset);
-
- Inherited::UpdateCoordinates();
-
- if (fQDOrigin != oldQDOrigin || fViewToQDOffset != oldViewToQDOffset)
- this->AdjustCtlMgrControl(kDontRedraw);
- } // TCtlMgr::UpdateCoordinates
-
-
- //========================================================================================
- // CLASS TScrollBar
- //========================================================================================
- #undef Inherited
- #define Inherited TCtlMgr
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TScrollBar, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TScrollBar constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TScrollBar::TScrollBar()
- {
- fDirection = hSel;
- fEventNumber = mHScrollBarHit;
- fHandlesFirstClicks = FALSE;
- } // TScrollBar::TScrollBar
-
- //----------------------------------------------------------------------------------------
- // TScrollBar destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TScrollBar::~TScrollBar()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::IScrollBar:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TScrollBar::IScrollBar(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- VHSelect itsDirection,
- long itsVal,
- long itsMin,
- long itsMax)
- {
- this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, gEmptyString, itsVal, itsMin, itsMax, scrollBarProc);
- fDirection = itsDirection;
-
- if (itsDirection == hSel)
- fEventNumber = mHScrollBarHit;
- else
- fEventNumber = mVScrollBarHit;
- } // TScrollBar::IScrollBar
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TScrollBar::GetStandardSignature() // override
- {
- return kStdScrollBar;
- } // TScrollBar::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TScrollBar::ReadFields(TStream* aStream) // override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fDirection = (VHSelect) aStream->ReadByte();
-
- long initialValue = aStream->ReadLong();
- long minimumValue = aStream->ReadLong();
- long maximumValue = aStream->ReadLong();
-
- this->CreateCMgrControl(gEmptyString, initialValue, minimumValue, maximumValue, scrollBarProc);
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TScrollBar::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TScrollBar::WriteFields(TStream* aStream) // override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteByte(fDirection);
-
- aStream->WriteLong(fLongVal);
- aStream->WriteLong(fLongMin);
- aStream->WriteLong(fLongMax);
- } // TScrollBar::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::ActionProc:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TScrollBar::ActionProc(short partCode)
- {
- Boolean backwards;
-
- if (partCode != 0)
- {
- backwards = ((partCode == kControlUpButtonPart) || (partCode == kControlPageUpPart));
-
- if ((backwards && (fLongVal > fLongMin)) || ((!backwards) && (fLongVal < fLongMax)))
- this->TrackScrollBar(partCode);
-
- this->Update(); // Make sure that we're in synch before
- // returning
- this->Focus(); // make sure i am looking at myself… e.e. cummings
- }
- } // TScrollBar::ActionProc
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::DeltaValue:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScrollBar::DeltaValue(VCoordinate delta)
- {
- if (delta != 0) // Ensure that delta does not cause an overflow (or underflow)
- this->SetLongVal(fLongVal + MinMax(fLongMin - fLongVal, delta, fLongMax - fLongVal), fShown);
- } // TScrollBar::DeltaValue
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScrollBar::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* /* event */,
- CPoint /* hysteresis */) // override
- {
- VCoordinate newLongValue;
-
- #if qDebug
- this->AssumeFocused();
- #endif
-
- CPoint theQDMouse = this->ViewToQDPt(theMouse);
- VCoordinate oldLongValue = fLongVal;
-
- CWhileFocused itsWhileFocused(this, kRedraw);
-
- switch (TestControl(fCMgrControl, theQDMouse))
- {
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- case kControlPageUpPart:
- case kControlPageDownPart:
- // note: the braces defeat an xlC warning
- {
- ControlActionUPP actionProc = NewControlActionProc(&ActionProcForTScrollBar);
- FailNIL(actionProc);
- TrackControl(fCMgrControl, theQDMouse, actionProc);
- actionProc = (ControlActionUPP)DisposeIfRoutineDescriptor((UniversalProcPtr)actionProc);
- }
-
- // This method MUST inform its superview of the change! Thanks to GLB!
- if (fLongVal != oldLongValue)
- this->HandleEvent(fEventNumber, this, NULL);
- break;
- case kControlIndicatorPart: // Thumb
- if (TrackControl(fCMgrControl, theQDMouse, NULL) == kControlIndicatorPart)
- {
- // If thumb is dragged to bottom of scroll bar then ensure that the new
- // long value is set to the maximum long value. We get killed by side
- // effects if we don't use a temporary variable here. This doesn't show up
- // in the TScrollerScrollBar class because this code is overridden, but it
- // will show up in derived classes that depend on this code
- if (this->GetVal() == this->GetMax())
- newLongValue = fLongMax;
- else
- newLongValue = ((long)GetVal() << fBitsToShift);
-
- this->SetLongVal(newLongValue, kRedraw);
-
- // This method MUST inform its superview of the change!
- if (fLongVal != oldLongValue)
- this->HandleEvent(fEventNumber, this, NULL);
- }
- break;
- }
- } // TScrollBar::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TScrollBar::TrackScrollBar:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TScrollBar::TrackScrollBar(short partCode)
- {
- this->DeltaValue((partCode == kControlPageUpPart) || (partCode == kControlUpButtonPart) ? -1 : 1);
- } // TScrollBar::TrackScrollBar
-
-
- //========================================================================================
- // CLASS TScrollerScrollBar
- //========================================================================================
- #undef Inherited
- #define Inherited TScrollBar
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TScrollerScrollBar, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TScrollerScrollBar::TScrollerScrollBar()
- {
- fScrollers = NULL;
- } // TScrollerScrollBar::TScrollerScrollBar
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::IScrollerScrollBar:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TScrollerScrollBar::IScrollerScrollBar(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- VHSelect itsDirection,
- long itsMax,
- TScroller* itsScroller)
- {
- this->IScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, 0, 0, itsMax);
- this->SetCMgrVisibility(this->IsActive());
-
- FailInfo fi;
- Try(fi)
- {
- fScrollers = NewList();
- #if qDebug
- fScrollers->SetEltType("TScroller");
- #endif
-
- this->AttachScroller(itsScroller);
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- } // TScrollerScrollBar::IScrollerScrollBar
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- TObject* TScrollerScrollBar::Clone() // override
- {
- TScrollerScrollBar * aScrollerScrollBar = (TScrollerScrollBar *)(Inherited::Clone());
-
- #if qDebug
- if (aScrollerScrollBar->fScrollers->GetSize() != 1)
- ProgramBreak("###TScrollerScrollBar.Clone: Unexpected number of scrollers!");
- #endif
-
- aScrollerScrollBar->fScrollers = NewList();
-
- return aScrollerScrollBar;
- } // TScrollerScrollBar::Clone
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TScrollerScrollBar::~TScrollerScrollBar()
- {
- {
- CObjectIterator iter(fScrollers);
-
- for (TScroller * theScroller = (TScroller *)iter.FirstObject(); iter.More(); theScroller = (TScroller *)iter.NextObject())
- if (theScroller->fScrollBars[fDirection] == this)
- theScroller->HaveScrollBar(NULL, fDirection);
- }
-
- fScrollers = (TList *)(FreeIfObject(fScrollers));
- } // TScrollerScrollBar::Free
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TScrollerScrollBar::GetStandardSignature() // override
- {
- return kStdScrollerScrollBar;
- } // TScrollerScrollBar::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TScrollerScrollBar::ReadFields(TStream* aStream) // override
- {
- Inherited::ReadFields(aStream);
-
- this->SetCMgrVisibility(this->IsActive());
-
- FailInfo fi;
- Try(fi)
- {
- fScrollers = NewList();
- #if qDebug
- fScrollers->SetEltType("TScroller");
- #endif
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- } // TScrollerScrollBar::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TScrollerScrollBar::WriteFields(TStream* aStream) // override
- {
- Inherited::WriteFields(aStream);
-
- } // TScrollerScrollBar::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::Activate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAActivate
-
- void TScrollerScrollBar::Activate(Boolean entering)// override
- {
- CWhileFocused itsWhileFocused(this, kRedraw);
-
- this->SetCMgrVisibility(entering);
- this->DrawContents();
- } // TScrollerScrollBar::Activate
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::AttachScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TScrollerScrollBar::AttachScroller(TScroller* itsScroller)
- {
- if (itsScroller)
- {
- // create a fake fIdentifier for TScrollerScrollBar, if needed
- if (fIdentifier == kNoIdentifier)
- {
- IDType tempID = itsScroller->fIdentifier;
- Ptr hiBytePtr = (Ptr) &tempID;
-
- if (fDirection == vSel)
- *hiBytePtr = 'v';
- else
- *hiBytePtr = 'h';
-
- fIdentifier = tempID;
- }
-
- fScrollers->Insert(itsScroller);
- itsScroller->HaveScrollBar(this, fDirection);
- }
- } // TScrollerScrollBar::AttachScroller
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::BeInPort:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
-
- void TScrollerScrollBar::BeInPort(GrafPtr itsPort)// override
- {
- Inherited::BeInPort(itsPort);
-
- this->SetCMgrVisibility(this->IsActive());
- } // TScrollerScrollBar::BeInPort
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScrollerScrollBar::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis) // override
- {
-
- #if qDebug
- this->AssumeFocused();
- #endif
-
- CPoint theQDMouse = this->ViewToQDPt(theMouse);
-
- CWhileFocused itsWhileFocused(this, kRedraw);
-
- if (TestControl(fCMgrControl, theQDMouse) == kControlIndicatorPart) // Thumb
- {
- if (TrackControl(fCMgrControl, theQDMouse, NULL) == kControlIndicatorPart)
- {
- // If thumb is dragged to bottom of scroll bar then ensure that
- // the new long value is set to the maximum long value.
- if (this->GetVal() == this->GetMax())
- fLongVal = fLongMax;
- else
- fLongVal = (this->GetVal() << fBitsToShift);
-
- long sBarDelta = 0;
- CObjectIterator iter(fScrollers);
-
- for (TScroller * theScroller = (TScroller *)iter.FirstObject(); iter.More(); theScroller = (TScroller *)iter.NextObject())
- sBarDelta += theScroller->ScrollRelative(fDirection, fLongVal);
-
- if (this->Focus() && (sBarDelta != 0))
- this->SetLongVal(fLongVal + sBarDelta, kRedraw);
- }
- }
- else
- Inherited::DoMouseCommand(theMouse, event, hysteresis);
- } // TScrollerScrollBar::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
-
- void TScrollerScrollBar::Draw(const VRect& area)// override
- {
- #if qDebug
- this->AssumeFocused();
- #endif
-
- if (!IsCMgrVisible())
- {
- CRGBColor savedBkColor;
-
- PenNormal();
- GetIfBkColor(savedBkColor);
- SetIfBkColor(gRGBWhite);
-
- CWhileFocused itsWhileFocused(this, kRedraw);
- CRect itsRect = (*fCMgrControl)->contrlRect;
-
- EraseRect(itsRect);
- FrameRect(itsRect);
- SetIfBkColor(savedBkColor);
- }
-
- Inherited::Draw(area);
- } // TScrollerScrollBar::Draw
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar::TrackScrollBar:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TScrollerScrollBar::TrackScrollBar(short partCode)
- {
- long sBarDelta = 0;
-
- CObjectIterator iter(fScrollers);
-
- for (TScroller * theScroller = (TScroller *)iter.FirstObject(); iter.More(); theScroller = (TScroller *)iter.NextObject())
- sBarDelta += theScroller->ScrollStep(fDirection, partCode);
-
- if (this->Focus())
- this->DeltaValue(sBarDelta);
- } // TScrollerScrollBar::TrackScrollBar
-
- //----------------------------------------------------------------------------------------
- // End of UControl.cp
-
- #pragma segment Inline
-